package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.constant.SymbolConsts;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.HighLevelPackAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.stereotype.Service;
import java.util.Objects;

/**
 * @version V1.0
 * @author:lxb
 * @Package
 * @date:2021/4/2
 */
@Service
@AttrHandler(HighLevelPackAttrHandler.class)
public class HighLevelPackAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Override
    public void handle(KiteAttr kiteAttr, KiteInst inst, AttrData attrData) {
        // 域名无忧高级套餐  对应的属性下拉框
        String[] values = KiteStringUtils.split(inst.getAttrValue("210004166"), SymbolConsts.COMMA);

        KiteAttr domain = inst.getAttr("200003826");
        if (KiteStringUtils.equalsAny("110007171",values)) {
            if (!KiteObjectUtils.isEmpty(domain)) {
                domain.setIsNull(KeyConsts.IFTRUE_F);
                domain.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
            }
        }else{
            if (Objects.nonNull(domain)){
                domain.setIsNull(KeyConsts.IFTRUE_T);
                domain.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
            }
        }
        //域名解析查询次数
        KiteAttr cache = inst.getAttr("210004163");
        if (KiteStringUtils.equalsAny("110007173",values)) {
            if (!KiteObjectUtils.isEmpty(cache)) {
                cache.setIsNull(KeyConsts.IFTRUE_F);
                cache.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
            }
        }else{
            if(Objects.nonNull(cache)){
                cache.setIsNull(KeyConsts.IFTRUE_T);
                cache.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
            }
        }
        //域名刷新缓存次数
        KiteAttr cache1 = inst.getAttr("210004164");
        if (KiteStringUtils.equalsAny("110007174",values)) {
            if (!KiteObjectUtils.isEmpty(cache1)) {
                cache1.setIsNull(KeyConsts.IFTRUE_F);
                cache1.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
            }
        }else{
           if (Objects.nonNull(cache1)){
               cache1.setIsNull(KeyConsts.IFTRUE_T);
               cache1.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
           }
        }
    }

    @Override
    public void handleStyle(KiteAttr kiteAttr, KiteInst kiteInst, AttrData attrData) {

    }
}
